package api

import (
	"context"
	"github.com/gin-gonic/gin"
	"go-likaladi-shop/common/base_util"
	"google.golang.org/protobuf/types/known/emptypb"
	"shop-web/goods-web/global"
)

func BannerList(ctx *gin.Context) {
	rsp, err := global.GoodsClient.BannerList(context.Background(), &emptypb.Empty{})
	// 检查是否存在错误，如果有错误则记录日志并返回错误响应
	if base_util.IsGrpcExitError(err, ctx, "[BannerList] 查询 【轮播图列表】") {
		return // 查询失败，直接返回
	}

	result := make([]interface{}, 0)
	for _, value := range rsp.Data {
		reMap, err := base_util.ProtoMapForJsonMarshal(value)
		if err != nil {
			return
		}
		result = append(result, reMap)
		//reMap := make(map[string]interface{})
		//reMap["id"] = value.Id
		//reMap["index"] = value.Index
		//reMap["image"] = value.Image
		//reMap["url"] = value.Url
		//result = append(result, reMap)
	}
	base_util.RespSuccess(result, ctx)
}

func BannerList2(ctx *gin.Context) {
	rsp, err := global.GoodsClient.BannerList(context.Background(), &emptypb.Empty{})
	// 检查是否存在错误，如果有错误则记录日志并返回错误响应
	if base_util.IsGrpcExitError(err, ctx, "[BannerList] 查询 【轮播图列表】") {
		return // 查询失败，直接返回
	}

	result := make([]interface{}, 0)
	for _, value := range rsp.Data {
		reMap, err := base_util.ProtoMapForProtoMarshal(value)
		if err != nil {
			return
		}
		result = append(result, reMap)
	}
	base_util.RespSuccess(result, ctx)
}

func CreateBanner(ctx *gin.Context) {
}

func DeleteBanner(ctx *gin.Context) {}

func UpdateBanner(ctx *gin.Context) {}
